#ifndef FILECONTENTDISK_H
#define FILECONTENTDISK_H

#include "FileContentBase.h"
#include "TestCasesBase.h"
#include <vector>
#include <wx/file.h>


class FileContentDisk: public FileContentBase {
  public:
    FileContentDisk();
    virtual ~FileContentDisk();
    virtual bool ReadFile( const wxString& fileName );
    virtual bool WriteFile( const wxString& fileName );
    virtual OffsetT GetSize();
    virtual OffsetT Read( void* buff, OffsetT position, OffsetT length );
    static TestCasesBase& GetTests();
    class TestData;
  protected:
    virtual ModificationData* BuildChangeModification( OffsetT position, OffsetT length, const void* data = 0 );
    virtual ModificationData* BuildAddModification( OffsetT position, OffsetT length, const void* data = 0 );
    virtual ModificationData* BuildRemoveModification( OffsetT position, OffsetT length );
    void SetBlock( const char* data, OffsetT pos, OffsetT lengthBefore, OffsetT lengthAfter );
    struct DataBlock {
      OffsetT start;
      OffsetT fileStart;
      OffsetT size;
      std::vector< char > data;
      bool IsFromDisk() { return data.empty(); }
    };
    DataBlock* InsertNewBlock( size_t blockIndex, OffsetT position );
    class DiskModificationData;
    wxString m_FileName;
    wxFile m_File;
    std::vector< DataBlock* > m_Contents;
    bool m_TestMode;
    void ClearBlocks();
    inline size_t FindBlock( OffsetT offset );
    inline void MergeBlocks( size_t startPosition );
    inline void ConsistencyCheck();
    bool WriteFileEasiest();
    bool WriteFileOnDisk();
    bool WriteFileTemporary();
    bool WriteToDifferentFile( const wxString& fileName );
    bool WriteToFile( wxFile& file );
    void ResetBlocks();
};

#endif
